﻿@model PagedList.IPagedList<AplicacionBase.Models.Post> 
           

@{
    ViewBag.Title = "Noticias";
}

<h2>Gestor de Noticias</h2>
<div id="prueba"></div>
<form method="get" action="/Post/Search">
    <fieldset>
        <legend>Buscador de noticias: </legend>
        <div class="editor-field">
          Buscar noticias que contengan: @Html.TextBox("criteria", ViewBag.CurrentFilter as string)&nbsp<input type="submit" value="Buscar" class="ebutton blue" />   
        </div>
            
    </fieldset>
</form>


<p>
    @Html.ActionLink("Nueva Noticia", "CreateAdmin", null, htmlAttributes: new { @class = "ebutton blue" })
</p>
<table>
    <tr>
        <th width = "150"  >
            Usuario
        </th>
        <th width = "150" >
            Título
        </th>
        <th >
            Resumen
        </th>
        <th width = "185">
            Fecha de Publicación
        </th>
        <th width = "100">
            Autorizado
        </th>
        <th width = "80">
            Principal
        </th>
        <th width = "60">
            Estado
        </th>
        <th width = "100">
            Acciones
        </th>        
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.User.FirstNames)
                @Html.DisplayFor(modelItem => item.User.LastNames)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Title)
            </td>
            <td style="text-align: justify;">
                @Html.DisplayFor(modelItem => item.Abstract)
            </td>
            <td style="text-align: center;">
                @Html.DisplayFor(modelItem => item.PublicationDate)
            </td>
            <td class="center">                
                @if (item.Autorized == 0)
                {
                    @Html.CheckBox("Autorizado", false, htmlAttributes: new { @id="CBA"+item.Id, @onclick = "AutorizarPost('" + item.Id + "')" });
                }
                else
                {
                    @Html.CheckBox("Autorizado", true, htmlAttributes: new { @id = "CBA" + item.Id, @onclick = "AutorizarPost('" + item.Id + "')" });
                }
            </td>
            <td class="center">
                @if (item.Main == 0)
                {
                    @Html.CheckBox("Principal", false, htmlAttributes: new { @id="CBM"+item.Id, @onclick = "PostPrincipal('" + item.Id + "')" });
                }
                else
                {
                    @Html.CheckBox("Principal", true, htmlAttributes: new { @id = "CBM" + item.Id, @onclick = "PostPrincipal('" + item.Id + "')" });
                }
            </td>
            <td class="center">
                @if (item.Estate == 0)
                {
                    @Html.CheckBox("Estado", false, htmlAttributes: new { @id="CBE"+item.Id, @onclick = "CambiarEstadoPost('" + item.Id + "')" });
                }
                else
                {
                    @Html.CheckBox("Estado", true, htmlAttributes: new { @id = "CBE" + item.Id, @onclick = "CambiarEstadoPost('" + item.Id + "')" });
                }
            </td>
            <td class="center">
                @Html.ActionLink(" ", "EditAdmin", new { id = item.Id }, htmlAttributes: new { @class = "btnedit", @title = "Editar" }) 
                @Html.ActionLink(" ", "DetailsAdmin", new { id = item.Id }, htmlAttributes: new { @class = "btndetails", @title = "Detalles" })
            </td>
            
        </tr>
    }
</table>

<div>
    Página @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
    de @Model.PageCount
     
    @if (Model.HasPreviousPage)
    {
        @Html.ActionLink("<<", "Index", new { page = 1 })
        @Html.Raw(" ");
        @Html.ActionLink("< Anterior", "Index", new { page = Model.PageNumber - 1 })
    }
    else
    {
        @:<<
        @Html.Raw("   ");
        @:< Anterior
    }
     
    @if (Model.HasNextPage)
    {
        @Html.ActionLink("Siguiente>", "Index", new { page = Model.PageNumber + 1 })
        @Html.Raw(" ");
        @Html.ActionLink(">>", "Index", new { page = Model.PageCount })
    }
    else
    {
        @:Siguiente >
        @Html.Raw(" ")
        @:>>
    }
</div>

<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" 
type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/menu.js")" type="text/javascript"></script>